UDP source port

S

slaskbrev1

Hi.
Im sending data over a SOCK_DGRAM socket, is it possible to define
what source port my program will use?
I guess one alternative is to craft the UDP header by myself, what
type of socket would I use then? Do I have to craft the IP header
aswell and use SOCK_RAW?

Thanks
 
A

Antoninus Twink

Im sending data over a SOCK_DGRAM socket, is it possible to define
what source port my program will use?

Yes - just set the sin_port field of the struct sockaddr *address
argument you give to bind(). (The default value of 0 for sin_port just
means "pick any available port".)
 
S

slaskbrev1

Yes - just set the sin_port field of the struct sockaddr *address
argument you give to bind(). (The default value of 0 for sin_port just
means "pick any available port".)

Thanks. It bothers me I didnt figure that out myself. :)
 
K

Keith Thompson

Im sending data over a SOCK_DGRAM socket, is it possible to define
what source port my program will use?
I guess one alternative is to craft the UDP header by myself, what
type of socket would I use then? Do I have to craft the IP header
aswell and use SOCK_RAW?

Please ask in a newsgroup that discusses your operating system,
perhaps comp.unix.programmer or one of the Windows groups.
 
I

ionic

Call bind() right after socket(), specify your local port and NIC
adapter in sockaddr_in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,255
Latest member
TopCryptoTwitterChannels

Latest Threads

Top