My program sends commands to a different computer running a udp server.
My problem is that each different node is running on a different udp port and the code needs to take that into account by allowing the port to change depending on a int variable.
The to code snippets ive provided show what i got working and what i think should work but doesn't.
This Works. -
-
const char* po = "49240";
-
-
if ((rv = getaddrinfo(lightIp, po, &hints, &servinfo)) != 0) {
-
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
-
-
}
-
-
This does not work. -
-
-
udpPort = 49240;
-
const char* po = (char*)udpPort;
-
-
-
if ((rv = getaddrinfo(lightIp, po, &hints, &servinfo)) != 0) {
-
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
-
-
}
-
-
I was finally able to get it working with the fallowing code: -
int udpPort = 12312;
-
char buf[5];
-
sprintf(buf,"%d",udpPort);
-
po = (char*) &buf;
-
-
if ((rv = getaddrinfo(lightIp, po, &hints, &servinfo)) != 0) {
-
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
-
}
-
-
4 6742
It looks like you're casting 49240 as a memory address. udpPort appears to be an integer, not a char*.
You might want:
udpPort = "49240";
const char* po = (char*) &udpPort;
OK but how would you take an integer (udpPort) containing the number 49240 and set it to something that getaddrinfo could use? I got close with (const char* po = "49240"; ) but i haven't been able to get that to be dynamic using a variable.
Thanks for the help.
I was finally able to get it working with the fallowing code: -
int udpPort = 12312;
-
char buf[5];
-
sprintf(buf,"%d",udpPort);
-
po = (char*) &buf;
-
-
if ((rv = getaddrinfo(lightIp, po, &hints, &servinfo)) != 0) {
-
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
-
}
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Hans Kamp |
last post by:
I found a useful client/server combination for newbies at
http://www.msdnaa.net/Resources/Display.aspx?ResID=1375
I typed both of the programs and I ran them on one of my 2 computers (I have
a...
|
by: Rob R. Ainscough |
last post by:
Does .NET framework 2.0 provide any TCP/IP support -- specifically looking
to write a Service that will monitor TCP/IP packets across various ports. I
was wondering if this can be accomplished via...
|
by: edcdave |
last post by:
I'm trying to get MoinMoin 1.5.4 running with Python 2.3.4 (installed
from an SCO Skunkworks binary). Python 2.3.4 (#1, Aug 27 2004,
18:22:39) on sco_sv3
One of the MoinMoin modules attempts to...
|
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...
|
by: mirandacascade |
last post by:
I noticed the following lines from the connect() method of the
HTTPConnection class within httplib:
for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
af, socktype,...
|
by: Maxim Veksler |
last post by:
Hello,
I wish to do some low level network stuff using python.
I've googled somewhat and came up with pylibpcap, trouble is I
can't compile it on my Ubuntu 6.10 workstation. Can someone please...
|
by: John Nagle |
last post by:
Here's a strange little bug. "socket.getaddrinfo" blows up
if given a bad domain name containing ".." in Unicode. The
same string in ASCII produces the correct "gaierror" exception.
Actually,...
|
by: Nathan |
last post by:
Hi,
I'm trying to do some network programming, but when I use 'struct
addrinfo' or getaddrinfo, I see errors:
gcc --std=c99 -Wall ipv6_test.c -o it
ipv6_test.c: In function `main':...
|
by: Karl Chen |
last post by:
I've discovered that since glibc 2.3.2, getaddrinfo(3) supports a
useful flag called AI_ADDRCONFIG. It turns off AAAA lookups if
the machine isn't configured for IPv6 (and similarly for IPv4,...
|
by: Adam01 |
last post by:
Im using cygwin to test the code of a server I am writing.
I've included sys/types.h, sys/socket.h, netdb.h, and arpa/inet.h.
And this is the output..
../../../sockets.cpp: In constructor...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
| |