a3a92abf1ca043aaaaaa79381afa316abaa00ace
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

1) /*
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

2)  * EtherPix library
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

3)  *
Stefan Schuermans removed version information...

Stefan Schuermans authored 13 years ago

4)  * Copyright 2010-2011 Stefan Schuermans <stefan schuermans info>
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

5)  *
6)  * This program is free software: you can redistribute it and/or modify
7)  * it under the terms of the GNU General Public License as published by
8)  * the Free Software Foundation, version 3 of the License.
9)  *
10)  *
11)  * This program is distributed in the hope that it will be useful,
12)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14)  * GNU General Public License for more details.
15)  *
16)  * You should have received a copy of the GNU Lesser General Public License
17)  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18)  */
19) 
20) #include <stdlib.h>
21) #include <string.h>
22) 
23) #include <intern/net.h>
24) #include <intern/parse.h>
25) 
26) /**
27)  * \brief parse two comma-separated numbers
28)  *
29)  * \param[in] text text to parse
30)  * \param[out] no1 first number parsed from text
31)  * \param[out] no2 second number parsed from text
32)  * \param[out] end location in text where parsing ended
33)  * \return 0 in case of success, -1 in case of error
34)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

35) int etp_parse_two_nos(char *text, unsigned int *no1, unsigned int *no2,
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

36)                       char **end)
37) {
38)   char *ptr1, *ptr2;
39)   unsigned long val1, val2;
40) 
41)   /* parse first number */
42)   val1 = strtoul(text, &ptr1, 0);
43)   if (ptr1 == text || *ptr1 != ',')
44)     return -1;
45) 
46)   /* skip comma */
47)   ptr1++;
48) 
49)   /* parse second number */
50)   val2 = strtoul(ptr1, &ptr2, 0);
51)   if (ptr2 == ptr1
52)       || (*ptr2 != 0 && *ptr2 != ' ' && *ptr2 != '\t' && *ptr2 != '\r'
53)           && *ptr2 != '\n'))
54)     return -1;
55) 
56)   /* return numbers and pointer behind end */
57)   *no1 = (unsigned int)val1;
58)   *no2 = (unsigned int)val2;
59)   *end = ptr2;
60)   return 0;
61) }
62) 
63) /**
64)  * \brief parse an address
65)  *
66)  * \param[in] test test to parse
67)  * \param[out] addr address parsed from text
68)  * \return 0 in case of success, -1 in case of error
69)  */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

70) int etp_parse_addr(char *text, struct sockaddr_in *addr)