| Код | #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h>
struct UdpHead { u_short src_port; u_short targ_port; u_short length; u_short checksum; };
char message[]="TEST"; char msgbuf[1024];
int main() { int sock; struct sockaddr_in addr; struct UdpHead udphead; char *ip="192.168.25.25";
if(sock=socket(AF_INET,SOCK_RAW,IPPROTO_UDP)<0) printf("error sock");
addr.sin_family=AF_INET; addr.sin_addr.s_addr=htonl(*ip);
udphead.targ_port=htons(139); udphead.length=htons(sizeof(udphead)+sizeof(message)); udphead.checksum=0;
memcpy((void *)msgbuf,(void *)&udphead,sizeof(udphead)); memcpy((void *)(msgbuf+sizeof(udphead)),(void *)message,sizeof(message));
sendto(sock,msgbuf,sizeof(udphead)+sizeof(message),0,(struct sockaddr *)&addr,sizeof(addr));
close(sock);
return 0; }
|
Отправляю udp пакет , и ловлю его сниффиром на хосте куда отправил, но увы пакет не дошел. Думаю трабл в проге , так как все файероволы отключены. |