How do I get port number from etc/services?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,

I need to bind a socket to a port that's specified in the
C:\windows\system32\drivers\etc\services file. Is there a
GetPortByServiceName() method in C#? If not, does anyone have any
suggestions on how best to do this?

Thanks,
John
 
Hi,

AFAIK there is not such a method, what you can do is read the
C:\windows\system32\drivers\etc\services file and parse it as needed. you
know that the format of a line is \d+\s+\w+

you will have to modify the \w+ part to include the service you want,
something like
"\w*" + ServiceName + "\w*"

Hope this help,
 
Back
Top