There is a need to work with the documentation in the source code. Of course there are a lot of ready-made tools, but I would like something that is integrated to emacs. So I decided to make a module for it on the base of org-mode. In the beginning the focus will be on the language C. The source code is located on github.
четверг, 8 сентября 2011 г.
The Creation Of Documentation And Access To It. Emacs-docs
вторник, 6 сентября 2011 г.
Cl-event-callback was Moved on the Bordeaux-threads.
I transfered this module on the bordeaux-threads. The core algorithms are the same.
It is necessary to add the thread-safety.
The source code is located on github.
It is necessary to add the thread-safety.
The source code is located on github.
Creating (Deleting) A Remote Branch With Git
Often I forget how creating a remote branch with git. So I wrote about it in this blog.
git push origin origin:refs/heads/new_branch
git checkout --track -b new_branch origin/new_branch
The next command was used for deleting a remote branch.
git push origin :heads/new_branch
If you want to get a list of remote branches.
git branch -r
понедельник, 5 сентября 2011 г.
The Catch of the Changing Routes For Ipv6 with Netlink.
IPv6 allows to make an auto configuring of the network interface via icmpv6 if forwarding is unsetted. In this case users can not track the change of theirs IP and routes in this mode. How can you detect this changes?
It is simple if you would use the netlink protocol. You can read about this protocol on http://www.ietf.org/rfc/rfc3549.txt.
I made the function "show_route" that was shows the changed routes into OS:
/*
buffer - the storage of netlink messages
size - the size of the received netlink messages
*/
void show_route(char *buffer, int size)
{
/*
nlmp - the netlink header
routemsg - the data of the netlink message
tb[RTA_MAX+1] - attributes of the route
*/
struct nlmsghdr *nlmp;
struct rtmsg *routemsg;
struct rtattr * tb[RTA_MAX+1];
/*
The buffer has following structure:
|nlmsghdr|data|nlmsghdr|data|....|nlmsghdr|data|
|--------------------size----------------------|
*/
for(nlmp = (struct nlmsghdr *)buffer; size > sizeof(*nlmp);){
int len;
int req_len;
/*Checking the netlink message*/
if (!NLMSG_OK(nlmp, size)) {
perror("NLMSG not OK\n");
return;
}
/*The length of netlink header*/
int len = nlmp->nlmsg_len;
/*Data length of netlink message*/
int req_len = len - sizeof(*nlmp);
/*Check type of message*/
/*If type is undefined then go to the next message*/
switch(nlmp->nlmsg_type){
case RTM_DELROUTE:
printf("A route was deleted\n");
break;
case RTM_NEWROUTE:
printf("A route was added\n");
break;
default:
size -= NLMSG_ALIGN(len);
nlmp = (struct nlmsghdr*)((char*)nlmp + NLMSG_ALIGN(len));
continue;
}
/*Get data of netlink message and get its atributte after that*/
routemsg = (struct rtmsg *)NLMSG_DATA(nlmp);
parseRtattr(tb, RTA_MAX, RTM_RTA(routemsg), len);
/*Printing the atributtes of route*/
if(tb[RTA_IIF]){
int iface;
iface = *(int*)RTA_DATA(tb[RTA_IIF]);
printf("An input iface is %d\n", iface);
}
if(tb[RTA_OIF]){
int iface;
iface = *(int*)RTA_DATA(tb[RTA_OIF]);
printf("An output iface is %d\n", iface);
}
if(tb[RTA_DST]){
char routeAddr[128];
inet_ntop(AF_INET6, RTA_DATA(tb[RTA_DST]), routeAddr, sizeof(routeAddr));
printf("Destination route is %s\n", routeAddr);
}else if (routemsg->rtm_dst_len) {
printf( "0/%d \n", routemsg->rtm_dst_len);
} else {
printf("Destination route is default\n");
}
if(tb[RTA_SRC]){
char routeAddr[128];
inet_ntop(AF_INET6, RTA_DATA(tb[RTA_SRC]), routeAddr, sizeof(routeAddr));
printf("Source route is %s\n", routeAddr);
}
if(tb[RTA_GATEWAY]){
char routeAddr[128];
inet_ntop(AF_INET6, RTA_DATA(tb[RTA_GATEWAY]), routeAddr, sizeof(routeAddr));
printf("Gateway is %s\n", routeAddr);
}
if(tb[RTA_PRIORITY]){
int metric ;
metric = *(int*)RTA_DATA(tb[RTA_PRIORITY]);
printf("Mertic is %d\n", metric);
}
/*And go to the next message*/
size -= NLMSG_ALIGN(len);
nlmp = (struct nlmsghdr*)((char*)nlmp + NLMSG_ALIGN(len));
}//for(nlmp = (struct nlmsghdr *)buffer; size > sizeof(*nlmp);){
}
Each segment of data of netlink message contains a header which defines its data type, and its length. Thereby the netlink message appear as following:
I use to parse attribute of route written bellow:
void parseRtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
{
memset(tb, 0, sizeof(struct rtattr *) * (max + 1));
/*Verify the data integrity of the data which succedes this rtattr header.*/
while(RTA_OK(rta, len)){
if(rta->rta_type <= max){
tb[rta->rta_type] = rta;
}
/*Return a pointer to the next rtattr header in the chain.*/
rta = RTA_NEXT(rta, len);
}
}
I created the main function after that:
int main(int argc, char *argv[])
{
/*for socket description*/
int nd = 0;
/*
The netlink socket address address structure, named struct sockaddr_nl is
passed to all calls which send or receive netlink sockets. This structure both
informs the kernel networking stack of a datagrams destination, and informs
a user-space program of a received frames source.
*/
struct sockaddr_nl *local;
/*The buffer for recsiving netlink`s message*/
char buffer[16384];
/*
The netlink address family uses the standard BSD socket API as its interface
between user-space programs and various kernel components. The creation
of a netlink socket is preformed in the exact same way as any other network
socket,via the socket library call.
*/
nd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
local = malloc(sizeof(struct sockaddr_nl ));
memset(local, 0, sizeof(struct sockaddr_nl));
local->nl_family = AF_NETLINK;
/*I want to catch ipv6 routes*/
local->nl_groups = RTMGRP_IPV6_ROUTE;
local->nl_pid = getpid();
if(bind(nd, (struct sockaddr *)local , sizeof(struct sockaddr_nl)) < 0){
printf("Error bind\n");
return 1;
}
/*After the socket is created and bound, I can read a using recvmsg() function*/
while(1){
/*msg is of struct msghdr defined in /include/linux/socket.h*/
struct msghdr msg;
/*
This iovec structure is filled with the data pointer
and the length of the data to be passed to the kernel
*/
struct iovec iov;
int size = 0;
iov.iov_base = buffer;
iov.iov_len = 16000;
msg.msg_name = &local;
msg.msg_namelen = sizeof(*local);
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
/*The MSG_DONTWAIT flag requests the call to return when it would block otherwise. */
size = recvmsg(nd, &msg, MSG_DONTWAIT);
if(size < 0){
if(errno == EINTR || errno == EAGAIN){
usleep(250000);
continue;
}
}
show_route(buffer, size);
}
}
четверг, 1 сентября 2011 г.
The Storage of Books
I want to create a repository of books with access via a web interface. I plan to use the Restas framework (CL language). I choose sqlite as the database engine (for single access). A module has been designed for accessing tables in database already. This module has a following functional: adding a new book, finding a book, getting books from the database and others. But I need to add a function (or functions) to get paths to books from the file system. The tables will be created in memory that would be permited easy testing.
For example:
You can to use all operations after that without creating a database`s file.
The next step is creating a user interface. The interface will be simple, because the web technology is new for me. The source code is located on github.
For example:
(in-package #:library-app)
(defparameter *db* (make-instance 'library-db :db-path ":memory:"))
(execute-non-query (slot-value *db* 'db-connect) "create table users (id integer primary key, user_name text not null, password text not null)")
You can to use all operations after that without creating a database`s file.
The next step is creating a user interface. The interface will be simple, because the web technology is new for me. The source code is located on github.
Подписаться на:
Сообщения (Atom)
