bsd

Can bind() socket to remote address?

孤者浪人 提交于 2019-12-02 04:02:17
问题 With the following snapshot of C code, I understand that, the address that bind() call binds to listfd , is the logical address of the local machine where this server program is running. Subsequently, server listens on listfd socket of that same machine. struct sockaddr_in serv_addr; listfd = socket(AF_INET, SOCK_STREAM, 0); bzero(&serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(8000); retval = bind

Non-greedy matching with grep

你离开我真会死。 提交于 2019-12-01 17:07:01
Non greedy matching as far as I know is not part of Basic Regular Expression (BRE) and Extended Regular Expression (ERE). However, the behaviour on different versions of grep (BSD and GNU) seems to suggest other wise. For example, let's take the following example. I have a string say: string="hello_my_dear_polo" Using GNU grep : Following are few attempts to extract hello from the string. BRE Attempt (fails) : $ grep -o "hel.*\?o" <<< "$string" hello_my_dear_polo Output yields entire string which suggest the non-greedy quantifier does not work on BRE. Note that I have only escaped ? since *

BSD Sockets - How to use non-blocking sockets?

…衆ロ難τιáo~ 提交于 2019-12-01 07:13:52
问题 I am trying to use non-blocking TCP sockets. The problem is that they are still blocking. The code is below - server code - struct sockaddr name; char buf[80]; void set_nonblock(int socket) { int flags; flags = fcntl(socket,F_GETFL,0); assert(flags != -1); fcntl(socket, F_SETFL, flags | O_NONBLOCK); } int main(int agrc, char** argv) { int sock, new_sd, adrlen; //sock is this socket, new_sd is connection socket name.sa_family = AF_UNIX; strcpy(name.sa_data, "127.0.0.1"); adrlen = strlen(name

UDP broadcast using CFSocket on IOS

这一生的挚爱 提交于 2019-12-01 05:50:24
Have been doing some google search and some reading on this subject but cannot seem to get it right no matter how much time i spent searching. What i want to do is to receive broadcast message of devices that are connected on my network by advertising my interest in their services that they supply. Using wireshark i can see the broadcast/notification messages from the network devices that i want to connect to sent over my network but not my broadcast search for interest of their services. But with network utility i can see that the socket is created but don't know which state it is in, whether

Is there a good reason to write my own daemonize function instead of using daemon(3)?

与世无争的帅哥 提交于 2019-12-01 05:13:52
问题 There are a lot of example implementations of daemons on the net. Most that I saw do not use the daemon(3) function to run the program in the background. Is that just a matter of taste, ignorance, or is there a good reason to write my own daemonize function? Is there a specific disadvantage in using daemon(3)? Is it insecure? 回答1: The BSD daemon() function is very limited and invites misuse. Only very few daemons may use this function correctly. The systemd man pages have a list of what a

What is the effect of changing system time on sleeping threads?

梦想的初衷 提交于 2019-12-01 02:56:55
问题 If you take a look at the clock_gettime() function, which is available in all BSDs and is actually defined as part of the POSIX standard, you see that there is support for at least three types of clocks (many systems support more than these clocks, but actually the POSIX standard only demands one to be present, all others are optional): CLOCK_REALTIME - POSIX demands this to be present. This is the wall time clock. CLOCK_MONOTONIC - No idea what this is (and what SI seconds mean), but I

bash printf literal verbatim string

落花浮王杯 提交于 2019-11-29 15:36:15
To make my code portable, I try to use printf rather than echo . But then printf "-dogs-cats" returns an error. A workaround in the present case is: printf "-";printf "dogs-cats" But is there a general, portable command (or an option with printf ) that will print an arbitrary string as a literal/verbatim, not try to interpret the string as a format? I work in BSD UNIX (on a Mac) but my objective is code that would work in other UNIX flavors as well. Just use -- after printf to let it know that no more arguments are to come and to consider the string as so: $ printf -- "-dogs-cats" -dogs-cats #

实战做项目如何选择开源许可协议(一)-了解协议

China☆狼群 提交于 2019-11-29 14:18:29
前段时间有件关于开源软件的事情挺热闹的,关于国内一个开发者把自己作品开源出来被别的公司的人拿去包装成自己的产品高价卖出去。大部分做开源软件的开发者都不太怎么关注版权这些,具体微博如下: hoowa_sun : 做开源后,发现大部分都被别人拿去学习,然后copy,然后自己闭源卖出去。这里不缺乏大公司,有一家公司拿我的开源系统修改后卖给了一个国内的运营商,卖的还非常贵至少几十万一套。所以我郑重的建议大家,做软件还是要英文版开源,中文版封闭不要开源。 在国内大家习惯了使用盗版、破解,看到这种免费的软件也觉得是理所当然的拿来主义,甚至直接封装到自己的商业组件卖出去。如果你正在这样做,马上停下来研究一下使用的这些开源组件的许可协议,不然某一天你会意外收到一封法院的传票。如果你在开发或者准备开发开源软件,但尚对开源许可协议不了解,也看下这篇文章,选择一种开源许可协议保护你的开源软件。 常见的开源许可协议有:GPL、LGPL、BSD、Apache Licence vesion 2.0、MIT。这些协议有什么区别呢? GPL ,全称 GNU General Public License。它的主要内容为:只要在一个软件中使用(“使用”指类库引用或者修改后的代码) GPL 协议的产品,则该软件产品必须也采用GPL协议,既必须也是开源和免费。这个协议就 不太适合商用软件

实战做项目如何选择开源许可协议(一)-了解协议

我怕爱的太早我们不能终老 提交于 2019-11-29 14:18:14
目前国内开源项目正在逐渐升温,中国也开始有不少优秀的开源项目突显出来。在大家摩拳擦掌准备加入开源大军时,也要知道这个圈子里的规则。技术人员不能只是研究技术,任何圈子都有规则,要知道了才能玩得好。前段时间有件关于开源软件的事情挺热闹的,关于国内一个开发者把自己作品开源出来被别的公司的人拿去包装成自己的产品高价卖出去。大部分做开源软件的开发者都不太怎么关注版权这些,具体微博如下: hoowa_sun : 做开源后,发现大部分都被别人拿去学习,然后copy,然后自己闭源卖出去。这里不缺乏大公司,有一家公司拿我的开源系统修改后卖给了一个国内的运营商,卖的还非常贵至少几十万一套。所以我郑重的建议大家,做软件还是要英文版开源,中文版封闭不要开源。 在国内大家习惯了使用盗版、破解,看到这种免费的软件也觉得是理所当然的拿来主义,甚至直接封装到自己的商业组件卖出去。如果你正在这样做,马上停下来研究一下使用的这些开源组件的许可协议,不然某一天你会意外收到一封法院的传票。如果你在开发或者准备开发开源软件,但尚对开源许可协议不了解,也看下这篇文章,选择一种开源许可协议保护你的开源软件。 常见的开源许可协议有:GPL、LGPL、BSD、Apache Licence vesion 2.0、MIT。这些协议有什么区别呢? GPL ,全称 GNU General Public License。它的主要内容为

详细介绍 BSD 开源协议

随声附和 提交于 2019-11-29 10:44:40
BSD开源协议是一个给于使用者很大自由的协议。可以自由的使用,修改源代码,也可以将修改后的代码作为开源或者专有软件再发布。当你发布使用了BSD协议的代码,或者以BSD协议代码为基础做二次开发自己的产品时,需要满足三个条件: 如果再发布的产品中包含源代码,则在源代码中必须带有原来代码中的BSD协议。 如果再发布的只是二进制类库/软件,则需要在类库/软件的文档和版权声明中包含原来代码中的BSD协议。 不可以用开源代码的作者/机构名字和原来产品的名字做市场推广。 BSD代码鼓励代码共享,但需要尊重代码作者的著作权。BSD由于允许使用者修改和重新发布代码,也允许使用或在BSD代码上开发商业软件发布和销 售,因此是对商业集成很友好的协议。很多的公司企业在选用开源产品的时候都首选BSD协议,因为可以完全控制这些第三方的代码,在必要的时候可以修改或者 二次开发。 转载于:https://my.oschina.net/gal/blog/200208 来源: https://blog.csdn.net/chenlian2409/article/details/100790347