C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-14-2007, 07:54 AM   #1
Registered User
 
Join Date: Jan 2006
Location: Belgrade
Posts: 72
Getting service port with getservbyname()

Hi,
the following code
Code:
int main()
{
	struct servent* se = getservbyname("telnet", "tcp");
	printf("%d\n", se->s_port);
}
prints as port number 5888 but in /etc/services this protocol has default port 23. And generally, getting port value with this function for any service differs from the values written in /etc/services. Why is that happening?
Thanks
karas is offline   Reply With Quote
Old 09-14-2007, 08:39 AM   #2
Registered User
 
Join Date: Oct 2001
Posts: 2,110
try converting it to host byte order.
Code:
printf("%d\n", ntohs(se->s_port));
robwhit is offline   Reply With Quote
Old 09-15-2007, 05:16 PM   #3
Registered User
 
Join Date: Jan 2006
Location: Belgrade
Posts: 72
It works, thanks.
karas is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FTP program jakemott Linux Programming 14 10-06-2008 01:58 PM
running my program as service daher Windows Programming 5 09-05-2008 12:30 PM
brace-enclosed error jdc18 C++ Programming 53 05-03-2007 05:49 PM
Segmentation Fault - Trying to access parallel port tvsinesperanto C Programming 3 05-24-2006 03:28 AM
DOS, Serial, and Touch Screen jon_nc17 A Brief History of Cprogramming.com 0 01-08-2003 04:59 PM


All times are GMT -6. The time now is 08:58 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22