Skip to content

Commit

Permalink
minor fix and use macro for ERRNO_IGNORE
Browse files Browse the repository at this point in the history
  • Loading branch information
danpodeanu committed Oct 11, 2023
1 parent 5109369 commit e4bb9ef
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/globals.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<li>DEBUG_LEVEL_INFO&#160;:&#160;<a class="el" href="udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997ad190887353b0664ff091b83d6387aa9b">udp-redirect.c</a></li>
<li>DEBUG_LEVEL_VERBOSE&#160;:&#160;<a class="el" href="udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997abef70e723b637a07777210af3cefc066">udp-redirect.c</a></li>
<li>EOK&#160;:&#160;<a class="el" href="udp-redirect_8c.html#acf2e4414e0bf0d331a111e70f9317434">udp-redirect.c</a></li>
<li>ERRNO_IGNORE_CHECK&#160;:&#160;<a class="el" href="udp-redirect_8c.html#ac55492e92f1e5fde0a623ffdf45671e9">udp-redirect.c</a></li>
<li>ERRNO_IGNORE_SET&#160;:&#160;<a class="el" href="udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e">udp-redirect.c</a></li>
<li>longopts&#160;:&#160;<a class="el" href="udp-redirect_8c.html#a94965649155359a4c4eb047af782bf22">udp-redirect.c</a></li>
<li>main()&#160;:&#160;<a class="el" href="udp-redirect_8c.html#a0ddf1224851353fc92bfbff6f499fa97">udp-redirect.c</a></li>
Expand Down
1 change: 1 addition & 0 deletions docs/globals_defs.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<div class="textblock">Here is a list of all macros with links to the files they belong to:</div><ul>
<li>DEBUG&#160;:&#160;<a class="el" href="udp-redirect_8c.html#ac1f6fbe3701c17626b9d9222002790a3">udp-redirect.c</a></li>
<li>EOK&#160;:&#160;<a class="el" href="udp-redirect_8c.html#acf2e4414e0bf0d331a111e70f9317434">udp-redirect.c</a></li>
<li>ERRNO_IGNORE_CHECK&#160;:&#160;<a class="el" href="udp-redirect_8c.html#ac55492e92f1e5fde0a623ffdf45671e9">udp-redirect.c</a></li>
<li>ERRNO_IGNORE_SET&#160;:&#160;<a class="el" href="udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e">udp-redirect.c</a></li>
<li>MAX_ERRNO&#160;:&#160;<a class="el" href="udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559">udp-redirect.c</a></li>
<li>NETWORK_BUFFER_SIZE&#160;:&#160;<a class="el" href="udp-redirect_8c.html#a4979fa449090ea6181c2f0a91fe512e7">udp-redirect.c</a></li>
Expand Down
27 changes: 14 additions & 13 deletions docs/navtreeindex0.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ var NAVTREEINDEX0 =
"structsettings.html#acdfde83a90fe7d0c4f621bf8b5d1dfae":[1,0,0,2],
"structsettings.html#ad19d72d81de785bc796800503cda86a6":[1,0,0,1],
"udp-redirect_8c.html":[2,0,0],
"udp-redirect_8c.html#a0ddf1224851353fc92bfbff6f499fa97":[2,0,0,7],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997":[2,0,0,6],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997a2458bd2178cc99bc6737bc528be5f61c":[2,0,0,6,0],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997a3849ab144f4ec0bc1433ce1ccfa389f4":[2,0,0,6,3],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997abef70e723b637a07777210af3cefc066":[2,0,0,6,2],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997ad190887353b0664ff091b83d6387aa9b":[2,0,0,6,1],
"udp-redirect_8c.html#a4979fa449090ea6181c2f0a91fe512e7":[2,0,0,5],
"udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e":[2,0,0,3],
"udp-redirect_8c.html#a795c40580eb8389eeb92c007ba8910a6":[2,0,0,8],
"udp-redirect_8c.html#a94965649155359a4c4eb047af782bf22":[2,0,0,11],
"udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559":[2,0,0,4],
"udp-redirect_8c.html#a0ddf1224851353fc92bfbff6f499fa97":[2,0,0,8],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997":[2,0,0,7],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997a2458bd2178cc99bc6737bc528be5f61c":[2,0,0,7,0],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997a3849ab144f4ec0bc1433ce1ccfa389f4":[2,0,0,7,3],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997abef70e723b637a07777210af3cefc066":[2,0,0,7,2],
"udp-redirect_8c.html#a1abe4a502b5a81ac9d4fc4ca3548b997ad190887353b0664ff091b83d6387aa9b":[2,0,0,7,1],
"udp-redirect_8c.html#a4979fa449090ea6181c2f0a91fe512e7":[2,0,0,6],
"udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e":[2,0,0,4],
"udp-redirect_8c.html#a795c40580eb8389eeb92c007ba8910a6":[2,0,0,9],
"udp-redirect_8c.html#a94965649155359a4c4eb047af782bf22":[2,0,0,12],
"udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559":[2,0,0,5],
"udp-redirect_8c.html#ac1f6fbe3701c17626b9d9222002790a3":[2,0,0,1],
"udp-redirect_8c.html#aca406131bb636c31134d300e0caae9b6":[2,0,0,9],
"udp-redirect_8c.html#ac55492e92f1e5fde0a623ffdf45671e9":[2,0,0,3],
"udp-redirect_8c.html#aca406131bb636c31134d300e0caae9b6":[2,0,0,10],
"udp-redirect_8c.html#acf2e4414e0bf0d331a111e70f9317434":[2,0,0,2],
"udp-redirect_8c.html#ae9a2954f00e12c29eff4ffd4e47f6d32":[2,0,0,10]
"udp-redirect_8c.html#ae9a2954f00e12c29eff4ffd4e47f6d32":[2,0,0,11]
};
3 changes: 2 additions & 1 deletion docs/search/all_3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ var searchData=
[
['eignore_0',['eignore',['../structsettings.html#a73ba0b9364d8e2f535fd5a0e9f0850ba',1,'settings']]],
['eok_1',['EOK',['../udp-redirect_8c.html#acf2e4414e0bf0d331a111e70f9317434',1,'udp-redirect.c']]],
['errno_5fignore_5fset_2',['ERRNO_IGNORE_SET',['../udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e',1,'udp-redirect.c']]]
['errno_5fignore_5fcheck_2',['ERRNO_IGNORE_CHECK',['../udp-redirect_8c.html#ac55492e92f1e5fde0a623ffdf45671e9',1,'udp-redirect.c']]],
['errno_5fignore_5fset_3',['ERRNO_IGNORE_SET',['../udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e',1,'udp-redirect.c']]]
];
3 changes: 2 additions & 1 deletion docs/search/defines_1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var searchData=
[
['eok_0',['EOK',['../udp-redirect_8c.html#acf2e4414e0bf0d331a111e70f9317434',1,'udp-redirect.c']]],
['errno_5fignore_5fset_1',['ERRNO_IGNORE_SET',['../udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e',1,'udp-redirect.c']]]
['errno_5fignore_5fcheck_1',['ERRNO_IGNORE_CHECK',['../udp-redirect_8c.html#ac55492e92f1e5fde0a623ffdf45671e9',1,'udp-redirect.c']]],
['errno_5fignore_5fset_2',['ERRNO_IGNORE_SET',['../udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e',1,'udp-redirect.c']]]
];
35 changes: 33 additions & 2 deletions docs/udp-redirect_8c.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@
<tr class="separator:acf2e4414e0bf0d331a111e70f9317434"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9998f145d5911cecdac6aa347ad08559" id="r_a9998f145d5911cecdac6aa347ad08559"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559">MAX_ERRNO</a>&#160;&#160;&#160;256</td></tr>
<tr class="separator:a9998f145d5911cecdac6aa347ad08559"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a683d9394d63aedb7ea0eca78e619156e" id="r_a683d9394d63aedb7ea0eca78e619156e"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e">ERRNO_IGNORE_SET</a>(X, Y)&#160;&#160;&#160;if ((Y) &gt;= 0 &amp;&amp; (Y) &lt; <a class="el" href="udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559">MAX_ERRNO</a>) (X)[(Y)] = 1;</td></tr>
<tr class="memitem:a683d9394d63aedb7ea0eca78e619156e" id="r_a683d9394d63aedb7ea0eca78e619156e"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e">ERRNO_IGNORE_SET</a>(X, Y)&#160;&#160;&#160;if ((Y) &gt;= 0 &amp;&amp; (Y) &lt; <a class="el" href="udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559">MAX_ERRNO</a>) (X)[(Y)] = 1</td></tr>
<tr class="separator:a683d9394d63aedb7ea0eca78e619156e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac55492e92f1e5fde0a623ffdf45671e9" id="r_ac55492e92f1e5fde0a623ffdf45671e9"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="udp-redirect_8c.html#ac55492e92f1e5fde0a623ffdf45671e9">ERRNO_IGNORE_CHECK</a>(X, Y)&#160;&#160;&#160;((Y) &gt;= 0 &amp;&amp; (Y) &lt; <a class="el" href="udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559">MAX_ERRNO</a> &amp;&amp; (X)[(Y)] == 1)</td></tr>
<tr class="separator:ac55492e92f1e5fde0a623ffdf45671e9"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="enum-members" name="enum-members"></a>
Enumerations</h2></td></tr>
Expand Down Expand Up @@ -260,6 +262,35 @@ <h2 class="memtitle"><span class="permalink"><a href="#acf2e4414e0bf0d331a111e70

<p>Readability: errno value for OK. </p>

</div>
</div>
<a id="ac55492e92f1e5fde0a623ffdf45671e9" name="ac55492e92f1e5fde0a623ffdf45671e9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac55492e92f1e5fde0a623ffdf45671e9">&#9670;&#160;</a></span>ERRNO_IGNORE_CHECK</h2>

<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define ERRNO_IGNORE_CHECK</td>
<td>(</td>
<td class="paramtype">&#160;</td>
<td class="paramname">X, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">&#160;</td>
<td class="paramname">Y&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td>&#160;&#160;&#160;((Y) &gt;= 0 &amp;&amp; (Y) &lt; <a class="el" href="udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559">MAX_ERRNO</a> &amp;&amp; (X)[(Y)] == 1)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Check if errno is in declared set </p>

</div>
</div>
<a id="a683d9394d63aedb7ea0eca78e619156e" name="a683d9394d63aedb7ea0eca78e619156e"></a>
Expand All @@ -283,7 +314,7 @@ <h2 class="memtitle"><span class="permalink"><a href="#a683d9394d63aedb7ea0eca78
<tr>
<td></td>
<td>)</td>
<td></td><td>&#160;&#160;&#160;if ((Y) &gt;= 0 &amp;&amp; (Y) &lt; <a class="el" href="udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559">MAX_ERRNO</a>) (X)[(Y)] = 1;</td>
<td></td><td>&#160;&#160;&#160;if ((Y) &gt;= 0 &amp;&amp; (Y) &lt; <a class="el" href="udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559">MAX_ERRNO</a>) (X)[(Y)] = 1</td>
</tr>
</table>
</div><div class="memdoc">
Expand Down
1 change: 1 addition & 0 deletions docs/udp-redirect_8c.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var udp_redirect_8c =
[ "settings", "structsettings.html", "structsettings" ],
[ "DEBUG", "udp-redirect_8c.html#ac1f6fbe3701c17626b9d9222002790a3", null ],
[ "EOK", "udp-redirect_8c.html#acf2e4414e0bf0d331a111e70f9317434", null ],
[ "ERRNO_IGNORE_CHECK", "udp-redirect_8c.html#ac55492e92f1e5fde0a623ffdf45671e9", null ],
[ "ERRNO_IGNORE_SET", "udp-redirect_8c.html#a683d9394d63aedb7ea0eca78e619156e", null ],
[ "MAX_ERRNO", "udp-redirect_8c.html#a9998f145d5911cecdac6aa347ad08559", null ],
[ "NETWORK_BUFFER_SIZE", "udp-redirect_8c.html#a4979fa449090ea6181c2f0a91fe512e7", null ],
Expand Down
16 changes: 11 additions & 5 deletions udp-redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@
/**
* Set the errno ignore boolean for a specific errno
*/
#define ERRNO_IGNORE_SET(X, Y) if ((Y) >= 0 && (Y) < MAX_ERRNO) (X)[(Y)] = 1;
#define ERRNO_IGNORE_SET(X, Y) if ((Y) >= 0 && (Y) < MAX_ERRNO) (X)[(Y)] = 1

/**
* Check if errno is in declared set
*/
#define ERRNO_IGNORE_CHECK(X, Y) ((Y) >= 0 && (Y) < MAX_ERRNO && (X)[(Y)] == 1)

/**
* @brief The available debug levels.
Expand Down Expand Up @@ -585,6 +590,7 @@ int main(int argc, char *argv[]) {
memset(errno_ignore, 0, MAX_ERRNO * sizeof(unsigned char));

ERRNO_IGNORE_SET(errno_ignore, EINTR); /* Always ignore EINTR */

if (s.eignore == 1) { /* List of harmless recvfrom / sendto errors. Possibly incorrect. */
ERRNO_IGNORE_SET(errno_ignore, EAGAIN);
ERRNO_IGNORE_SET(errno_ignore, EHOSTUNREACH);
Expand Down Expand Up @@ -626,7 +632,7 @@ int main(int argc, char *argv[]) {
if (ufds[0].revents & POLLIN || ufds[0].revents & POLLPRI) {
if ((recvfrom_retval = recvfrom(lsock, network_buffer, sizeof(network_buffer), 0,
(struct sockaddr *)&endpoint, (socklen_t *)&endpoint_len)) == -1) {
if (errno < 0 || errno > MAX_ERRNO || errno_ignore[errno] == 0) {
if (!ERRNO_IGNORE_CHECK(errno_ignore, errno)) {
perror("recvfrom");
DEBUG(DEBUG_LEVEL_INFO, "Listen cannot receive (%d)", errno);

Expand Down Expand Up @@ -660,7 +666,7 @@ int main(int argc, char *argv[]) {

if ((sendto_retval = sendto(ssock, network_buffer, recvfrom_retval, 0,
(struct sockaddr *)&caddr, sizeof(caddr))) == -1) {
if (errno < 0 || errno > MAX_ERRNO || errno_ignore[errno] == 0) {
if (!ERRNO_IGNORE_CHECK(errno_ignore, errno)) {
perror("sendto");
DEBUG(DEBUG_LEVEL_ERROR, "Cannot send packet to send port (%d)", errno);

Expand All @@ -686,7 +692,7 @@ int main(int argc, char *argv[]) {
if (ufds[1].revents & POLLIN || ufds[1].revents & POLLPRI) {
if ((recvfrom_retval = recvfrom(ssock, network_buffer, sizeof(network_buffer), 0,
(struct sockaddr *)&endpoint, (socklen_t *)&endpoint_len)) == -1) {
if (errno < 0 || errno > MAX_ERRNO || errno_ignore[errno] == 0) {
if (!ERRNO_IGNORE_CHECK(errno_ignore, errno)) {
perror("recvfrom");
DEBUG(DEBUG_LEVEL_INFO, "Send cannot receive packet (%d)", errno);

Expand All @@ -709,7 +715,7 @@ int main(int argc, char *argv[]) {

if ((sendto_retval = sendto(lsock, network_buffer, recvfrom_retval, 0,
(struct sockaddr *)&previous_endpoint, sizeof(previous_endpoint))) == -1) {
if (errno < 0 || errno > MAX_ERRNO || errno_ignore[errno] == 0) {
if (!ERRNO_IGNORE_CHECK(errno_ignore, errno)) {
perror("sendto");
DEBUG(DEBUG_LEVEL_INFO, "Cannot send packet to listen port (%d)", errno);

Expand Down

0 comments on commit e4bb9ef

Please sign in to comment.