<div dir="ltr"><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">I am curious: apart from a training prospective at code digging, what was the goal?<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">In other words, where did you expect the IP address to come from, if not from a system network socket?<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)"><br>Have a nice week-end,<br></div><div class="gmail_extra"><div><div class="gmail_signature" data-smartmail="gmail_signature"><font size="1"><span style="color:rgb(102,102,102)">---<br></span><b><span style="color:rgb(102,102,102)">B. R.</span></b><span style="color:rgb(102,102,102)"></span></font></div></div>
<br><div class="gmail_quote">On Sat, Feb 4, 2017 at 12:02 AM, Paul Nickerson <span dir="ltr"><<a href="mailto:pnickerson@cashstar.com" target="_blank">pnickerson@cashstar.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class=""><div>> Reading that file, the next likely looking line is:</div><div>>             c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->socklen,</div><div>>                                              c->addr_text.data,</div><div>>                                              ls->addr_text_max_len, 0);</div><div><br></div></span><div>Thank you for the boost. From what you said, it looks like the variable is constructed from c->sockaddr</div><div><br></div><div>src/event/ngx_event_accept.c<br></div><div>line 167<br></div><div>c->sockaddr = ngx_palloc(c->pool, socklen);<br></div><div><br></div><div>I chased that down, and it looks like ngx_palloc only allocates some memory; it doesn't fill it. Moving on.</div><div><br></div><div><div>line 173</div><div>ngx_memcpy(c->sockaddr, &sa, socklen);</div></div><div><br></div><div>It looks like ngx_memcpy is a wrapper around the standard C library function memcpy. For memcpy(A, B, C), it copies to destination A from source B, and it does amount C. So now I want to know where &sa comes from.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">line 70</div><div class="gmail_extra">s = accept(lc->fd, &sa.sockaddr, &socklen);</div><div class="gmail_extra"><br></div><div class="gmail_extra">Here, &sa.sockaddr is being sent into something. I think &sa.sockaddr becomes c->sockaddr, so I chase this.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Bash</div><div class="gmail_extra">man 2 accept<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">accept is a Linux system call: "accept a connection on a socket"</div><div class="gmail_extra">int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">"The argument addr is a pointer to a sockaddr structure.  This</div><div class="gmail_extra">structure is filled in with the address of the peer socket, as known</div><div class="gmail_extra">to the communications layer.  The exact format of the address</div><div class="gmail_extra">returned addr is determined by the socket's address family (see</div><div class="gmail_extra">socket(2) and the respective protocol man pages).  When addr is NULL,</div><div class="gmail_extra">nothing is filled in; in this case, addrlen is not used, and should</div><div class="gmail_extra">also be NULL."</div><div class="gmail_extra"><br></div><div class="gmail_extra">And so, the answer to my question appears to be: $remote_addr is constructed from "struct sockaddr *addr" of the "accept" Linux system call. It is the address of the peer socket.</div><div class="gmail_extra"><br></div><div class="gmail_extra">I am going to read through socket(2) and the respective protocol man pages, but at this point we're outside of NGINX, and so the scope of this mailing list.</div><div class="gmail_extra">Thank you again for your help.</div><span class="HOEnZb"><font color="#888888"><div class="gmail_extra"><br></div><div class="gmail_extra"> ~ Paul Nickerson</div></font></span></div></div><div class="HOEnZb"><div class="h5">

<br>
<div><div><span style="border-collapse:collapse"><p style="margin-top:0px;margin-right:0in;margin-bottom:5pt;margin-left:0in"><span style="font-size:7.5pt"><font color="#666666" face="tahoma, sans-serif"><b>CONFIDENTIALITY NOTICE</b></font></span></p></span></div></div><div><span style="border-collapse:collapse"><p><span style="color:rgb(102,102,102);font-family:tahoma,sans-serif;font-size:10px">The attached information is PRIVILEGED AND CONFIDENTIAL and is intended only for the use of the addressee named above.  If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, please be aware that any dissemination, distribution or duplication of this communication is strictly prohibited. If you receive this communication in error, please notify us immediately by telephone, delete the message and destroy any printed copy of the message. Thank you.</span></p></span></div></div></div><br>______________________________<wbr>_________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx</a><br></blockquote></div><br></div></div>