why this code is not working?Code:int main(){ struct servent* se = getservbyname("tejo.ist.utl.pt", "udp"); printf("%d\n", se->s_port); printf("%d\n", ntohs(se->s_port)); }
why this code is not working?Code:int main(){ struct servent* se = getservbyname("tejo.ist.utl.pt", "udp"); printf("%d\n", se->s_port); printf("%d\n", ntohs(se->s_port)); }
What do you think getservbyname does?
getservbyname(3)
It gets a service, not a server.
The name should be things like "ftp" or "www", not an IP address.
Your code should also check for NULL pointers.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
ok, what is the diff betwen service and IP?
service is the port?
i have seen this page:
services(5) - Linux manual page
but i still do not understand it properly
Perhaps you should explain what it is you're trying to do, rather than us guess based on your incorrect use of an API.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
here : services(5) - Linux manual page i found this phrase: port number (and protocol) for its service
and here : getaddrinfo(3) - Linux manual page
i found the name service which is treated as the port. so i am confused
i am trying to better understand the function getservbyname() with some examples