Destination: I wanted to try to make an UDP socket without any example.
Code:
.386                   ; minimum processor needed for 32 bit

.model flat, stdcall ; FLAT memory model & STDCALL calling
option casemap :none ; set code to case sensitive
; ###########################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
include \masm32\include\wsock32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\wsock32.lib
; ###########################
Port equ 180
; ###########################
.data
caption db "Client",0
text db "This was sent from client!",0
ipServer db "127.0.0.1",0
CompName db "Valka",0
.data?
hSocket dd ?
WSAdata WSADATA <>
sin sockaddr_in <>
sin_addr in_addr <>
buff db 256 dup (?)
; ###########################
.code
start:

invoke WSAStartup,101h,offset WSAdata
invoke gethostbyname,offset CompName
test eax,eax
jz exit

assume eax:ptr hostent
mov ebx,[eax].h_list
mov ebx,[ebx]
mov ebx,[ebx]
mov sin.sin_addr,ebx
assume eax:nothing
invoke htons, Port
mov sin.sin_port, ax
mov sin.sin_family, AF_INET

invoke socket,AF_INET,SOCK_DGRAM,IPPROTO_UDP
cmp eax,INVALID_SOCKET
je exit
mov hSocket,eax

invoke sendto,
hSocket,\ ; Socket
offset text,\ ; Data buffer
sizeof text,\ ; Length of data
0,\ ; Flags
offset sin,\ ; Server address
sizeof sin ; Length of address
cmp eax,SOCKET_ERROR
je closeskt

invoke recvfrom,
hSocket,\ ; Socket
offset buff,\ ; Receive buffer
256,\ ; Length of receive buffer
0,\ ; Flags
offset sin,\ ; Buffer to receive sender's address
sizeof sin ; Length of address buffer
cmp eax,SOCKET_ERROR
je closeskt

invoke MessageBoxA,0,offset buff,offset caption,0

closeskt:
invoke closesocket,hSocket
exit:
invoke WSACleanup
invoke ExitProcess,0
end start
Result: Crash!

Question: Why?
Posted on 2003-05-13 05:59:24 by zabnik
Interesting it did not crash on my com. What os are you using? I am using win2ksp3
Posted on 2003-05-13 07:06:25 by roticv
win98se maybe one of dll bugged in my system:

CLIENT caused an invalid page fault in
module MSAFD.DLL at 0167:7b41290e.
Posted on 2003-05-13 07:12:14 by zabnik
I have no UDP samples, can some one post one I tryed to find samples but all on C++ I completly not understand C+ It's hard as HELL :(

M$ Visual C++ is very stupid, It can't compile OWN GENERATED source codes :grin:
Posted on 2003-05-13 14:02:58 by zabnik
I can't code in C++
I'm NOT a C coder.

I CAN help you to convert c/c++ to masm format.
I'm becoming somewhat of an expert at that :tongue:
If you post a C example here, I'll spend some time converting it in this forum, so that others may benefit from the exercise also.
Posted on 2003-05-14 01:30:27 by Homer