You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-34Lines changed: 40 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,48 +10,54 @@ The library should be compilable to any platform as it is written in ANSI C. It
10
10
11
11
## API
12
12
### Parsing
13
-
**`pp_parse()`**: parsing a PROXY protocol header. Parameters:
14
-
*`uint8_t *pkt`: Pointer to a buffer with the data to parse. Normally it will be the buffer used to peek data from a socket.
15
-
*`uint32_t pktlen`: Data's length. Normally it will be the return value of a `recv(MSG_PEEK)`.
16
-
*`pp_info_t *proxy_info`: Pointer to a `pp_info_t` variable which will be used to save all the extracted information of the PROXY protocol header including the TLVs
17
-
*`return value: int32_t`: The length of the PROXY protocol header in case of success or a negative integer in case of error. You can use `pp_strerror()` to get a descriptive error message. In case the data dont't match any of the v1/v2 signatures `0` is returned.
*`pp_info_t *pp_info`: The `pp_info_t` used in the `pp_parse()`
23
-
*`uint8_t type`: The type of the TLV you are looking for as per the specification e.g. PP2_TYPE_AWS, PP2_TYPE_AZURE etc.
24
-
*`uint8_t subtype`: The subtype of the TLV you are looking for (in case it is needed else 0 to get it ignored) as per the specification e.g. PP2_SUBTYPE_AWS_VPCE_ID, PP2_SUBTYPE_AZURE_PRIVATEENDPOINT_LINKID
25
-
*`uint16_t *value_len_out`: The length of the value so that applications can copy and use the value properly
26
-
*`return value: uint8_t *`: Pointer to the value. In case the value is a string e.g. PP2_TYPE_AWS-PP2_SUBTYPE_AWS_VPCE_ID then the buffer is NULL terminated so that it can be used directly for string operations like `strcmp()` etc. **Do not manipulate these data in any way, rather make copies of them if you need to modify them.**
24
+
You shall not pass your `pp_info_t` variable to `pp_parse()` again without first clearing it with `pp_info_clear()`
27
25
28
-
**`pp_info_clear()`**: clearing a `pp_info_t` structure. You **MUST** use it. Parameter:
29
-
*`pp_info_t *pp_info`: A pointer to the `pp_info_t` used in `pp_parse()`
26
+
**`void pp_info_clear(pp_info_t *pp_info)`**
30
27
31
-
It basically clears the saved TLVs structure. For v1 it is not really needed as there are not any TLVs but to be safe always use it! A PROXY protocol sender might change from v1 to v2 so better to have your application prepared.
28
+
Clears the `pp_info_t` structure and frees any allocated memory associated with it. Shall always be called after a call to `pp_parse()`
29
+
*`pp_info`: Pointer to a filled `pp_info_t` structure which has been used to a previous call to `pp_parse()`
Searches for the specified TLV and returns its value
34
+
*`pp_info` Pointer to a `pp_info_t` structure used in `pp_parse()`
35
+
*`length` Pointer to a `uint16_t` where the TLV's value length will be set
36
+
*`return` Pointer to a buffer holding the TLV's value if found else `NULL`. In case of US-ASCII value the buffer is `NULL` terminated
32
37
33
38
### Creating
34
-
**`pp_create_hdr()`**: create a PROXY protocol header. Parameters:
35
-
*`uint8_t version`: `1` or `2` depending on the PROXY protocol version you want to use.
36
-
*`uint8_t fam`: Transport and address family. The values match exactly the specification:
37
-
* v2
38
-
*`'\x00'` : UNSPEC
39
-
*`'\x11'` : TCP over IPv4
40
-
*`'\x12'` : UDP over IPv4
41
-
*`'\x21'` : TCP over IPv6
42
-
*`'\x22'` : UDP over IPv6
43
-
*`'\x31'` : UNIX stream
44
-
*`'\x32'` : UNIX datagram
45
-
* v1
46
-
*`AF_INET`
47
-
*`AF_INET6`
48
-
*`pp_info_t *pp_info` : Pointer to a filled `pp_info_t` structure. Note that at the moment tlvs from the `tlv_array_t tlv_array` inside it will not be included in the header. This functionality will be added with the next release.
49
-
*`uint32_t *pp_hdr_len`: Output parameter where the length of the the PROXY protocol header will be stored.
50
-
*`uint32_t *error`: Outpur parameter where its value will be set to a negative integer in case of error or `ERR_NULL` in case of success. You can use `pp_strerror()` to get a descriptive error message
51
-
*`return value: uint8_t *`: Pointer to a dynamically allocated buffer where the PROXY protocol header exists. Shall be freed with `free()`
0 commit comments