Answer the question
In order to leave comments, you need to log in
How to force the sender port?
Can I force the first 2 bytes of a UDP packet? Not the datagram itself, but the UDP headers?
Answer the question
In order to leave comments, you need to log in
You can by calling bind() on the socket and specifying the port in the sockaddr_in structure.
int sock;
unsigned short port = 666;
struct sockaddr_in sin;
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
bind(sock,(struct sockaddr *)&sin, sizeof(sin));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question