473,499 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UDP source port

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
Jun 27 '08 #1
4 4823
On 17 Apr 2008 at 9:34, sl********@gmail.com wrote:
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".)

Jun 27 '08 #2
On 17 Apr, 12:43, Antoninus Twink <nos...@nospam.invalidwrote:
On 17 Apr 2008 at 9:34, slaskbr...@gmail.com wrote:
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".)
Thanks. It bothers me I didnt figure that out myself. :)
Jun 27 '08 #3
sl********@gmail.com writes:
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.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #4
Call bind() right after socket(), specify your local port and NIC
adapter in sockaddr_in.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3650
by: Monica Ferrero | last post by:
Hi! I'm not sure if this is the most adequate mySQL list for this post. If not, please indicat me which one I should use... I'm using Tomcat 4.1.24 with Apache 2 and MySQL 4.0.13. I have the...
4
2481
by: kj | last post by:
I consider myself quite proficient in C and a few other programming languages, but I have never succeeded in understanding a largish program (such as zsh or ncurses) at the source level. ...
1
3062
by: Jabadia | last post by:
Hi , I would like to know if it is possible to 'build' the TCP header with Source port / destination port , and with FLAGs i.e. SYN flag , sequence etc. I know this can be done in C++ of course...
2
3800
by: joe | last post by:
Has anyone seen any source code that shows how to use the serial port in VB 2005 (System.IO.Port)? Especially how to use the asynchronous read? John
3
2753
by: Stefan Schwarzer | last post by:
Hello, from time to time I want to inspect the source code of projects on remote computers.(*) I've googled for one or two hours but didn't find anything helpful. :-/ I'm looking for something...
135
7339
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
3
11721
by: Maksim Kasimov | last post by:
Hi, how to set source ip-address when do __socket.connect((host, port)) on a machine that have a several ip-adresses? many thanks for advice. __socket = socket.socket(socket.AF_INET,...
3
1251
by: jeremy.todter | last post by:
I have a question...obviously I am developing an application, or two applications using c++ and openGL. They involve a basic structure where approximately 70 percent of the framework applies to...
34
4051
by: mr.polik | last post by:
Is it legal to do something like this: #include "x.c" in other source file? And is it good idea? Thank you in advance for your answers, Igor.
0
1196
by: kellyonlyone | last post by:
E-XD++ MFC Library Enterprise Edition V11.0 is released (100% MFC/C++ Source Code)! ("The only Flow/Diagramming Kits that provides full source code of components for MFC and ActiveX in a single...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.