UDP source port number when using RAW socket??

UDP source port number when using RAW socket??

Post by Andre » Tue, 29 Jun 2004 19:35:21



Hello Everyone

I have created an application that runs as a client on a ADSL modem
and communicates with a server on a Windows/MAC using as RAW socket
with:
        sk = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));

With this socket I can send RAW data to the server that listens on
62828 . When I send I create my own ethernet, IP and UDP and send it
out on my eth0 interface. This all works fine and my server receives
the data correctly and responds. However now I have a question what
number to assign to my source port number on UDP when creating my
packet on the client??

From what I understand when using a UDP socket and having the network
stack creating the message the UDP source port number is taken from an
internal list. This ensures that no applications will select the same
port numbers when sending out data. But since I create my own packets
and send them out using RAW socket I can just give and number as UDP
source port number and I feel that this is not correct. If I am
unlucky I will create a conflict having 2 applications(my client) and
another one both sending out on the same port.

So my question is:
1) How do I get "hold" of a valid UDP port number that I can assign to
my RAW packet?
2) Is there some sort of API I can call and if so what?
3) What are the implications/problems if one for some reason have two
applications sending out data on the same port number?

Any input and advice is greatly appreciated.

Regards
Rikard

 
 
 

UDP source port number when using RAW socket??

Post by Steve Wa » Wed, 30 Jun 2004 07:41:03




>Hello Everyone

>I have created an application that runs as a client on a ADSL modem
>and communicates with a server on a Windows/MAC using as RAW socket
>with:
>        sk = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));

>With this socket I can send RAW data to the server that listens on
>62828 . When I send I create my own ethernet, IP and UDP and send it
>out on my eth0 interface. This all works fine and my server receives
>the data correctly and responds. However now I have a question what
>number to assign to my source port number on UDP when creating my
>packet on the client??

Why are you bothering with raw packets if you're redoing all of the
work that the IP and UDP code does?

Quote:>So my question is:
>1) How do I get "hold" of a valid UDP port number that I can assign to
>my RAW packet?

Maintain the same list, like the UDP code does.

Quote:>2) Is there some sort of API I can call and if so what?

Probably not.

Quote:>3) What are the implications/problems if one for some reason have two
>applications sending out data on the same port number?

Depends on the protocol.  If the other end uses the port you're sending
from as a place to send its data, you'll have to figure out how to
differentiate the two types of traffic.  If the remote has a hardcoded
port that it sends to, then it doesn't matter what source port you
use.
--
Steve Watt KD6GGD  PP-ASEL-IA          ICBM: 121W 56' 57.8" / 37N 20' 14.9"

   Free time?  There's no such thing.  It just comes in varying prices...

 
 
 

1. UDP source port number when using RAW socket??

Hello Everyone

I have created an application that runs as a client on a ADSL modem
and communicates with a server on a Windows/MAC using as RAW socket
with:
        sk = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));

With this socket I can send RAW data to the server that listens on
62828 . When I send I create my own ethernet, IP and UDP and send it
out on my eth0 interface. This all works fine and my server receives
the data correctly and responds. However now I have a question what
number to assign to my source port number on UDP when creating my
packet on the client??

From what I understand when using a UDP socket and having the network
stack creating the message the UDP source port number is taken from an
internal list. This ensures that no applications will select the same
port numbers when sending out data. But since I create my own packets
and send them out using RAW socket I can just give and number as UDP
source port number and I feel that this is not correct. If I am
unlucky I will create a conflict having 2 applications(my client) and
another one both sending out on the same port.

So my question is:
1) How do I get "hold" of a valid UDP port number that I can assign to
my RAW packet?
2) Is there some sort of API I can call and if so what?
3) What are the implications/problems if one for some reason have two
applications sending out data on the same port number?

Any input and advice is greatly appreciated.

Regards
Rikard

2. KNE100TX can't ping modem, but DHCP works

3. number of local udp port for broadcast socket

4. RH 5.0 & ppp

5. How to receive UDP and ICMP packet using one UDP socket, (Path MTUD)

6. write to /dev/nit question ?

7. Q: Raw sockets to buypass tcp/udp?

8. Help with sed

9. raw sockets and UDP broadcast : a strange phenomenon

10. Ignore all incoming udp/ip and udp/ip on all ports, except open ports?

11. ipchains/TCP/UDP, Why should I open UDP ports so that my TCP ports can work?

12. Overhead in large number of UDP/IP sockets?

13. get the real IP number from an udp socket.