user5520817
user5520817

Reputation:

Passing an IP Address string in C

I am trying to create a header file, within the header file I want to create a string to pass an IP address into my network file (/etc/network/interfaces)

Currently I have a header file set up and it includes the following:

char Board_IP[] = "192.168.40.3";
int n1, n2, n3, n4;
sscanf(ip, "%d.%d.%d.%d", &n1, &n2, &n3, &n4).

Then in my network file:

 address n1.n2.n3.n4

Whenever I try to restart my network, I always receive an error saying:

Reconfiguring network interfaces...Error: an inet prefix is expected rather than "n1.n2.n3.n4/255.255.255.224"

I know this is probably a simple question, but I am fairly new to this and would greatly appreciate some help.

Thank You!

Upvotes: 1

Views: 637

Answers (1)

Idos
Idos

Reputation: 15320

Try using the inet.pton function (the "reversed" function is inet.ntop if needed afterwards).

Upvotes: 1

Related Questions