參考資料:
Linux Kernel(3)- procfs
寫入與讀取 /proc 檔案
Linux Device Drvier使用flip_open來讀取檔案
核心進行開檔,讀檔與寫檔的程式作為範例
[Linux Kernel] 讀取 /proc 底下資料最佳方法: seq_file interface
Linux kernel內讀寫檔案
2014年12月22日 星期一
2014年12月9日 星期二
NTP client
要在router上自行更新時間,就必需要用到NTP service
參考資料:
NTP - 網路校時
解决ntp的错误 no server suitable for synchronization found
Linux RTC 時間對時校正
NTP协议以及ntpclinet使用
2012-09-15-NtpClient 选项用法
在linux中如何讀取並修改系統時間?
使用ntpdate更新系统时间
get ip address by DNS
目前要解析DNS去解析IP,
但是gethostbyname並不支援IPv6,
但有找到getaddrinfo可以達到同樣的功能,
而且同時有支援IPv4與IPv6
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
int main(int argc, char *argv[])
{
struct addrinfo hints, *res, *p;
int status;
char ipstr[INET6_ADDRSTRLEN];
if (argc != 2) {
fprintf(stderr,"usage: showip hostname\n");
return 1;
}
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // AF_INET or AF_INET6 to force version
hints.ai_socktype = SOCK_STREAM;
if ((status = getaddrinfo(argv[1], NULL, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
return 2;
}
printf("IP addresses for %s:\n\n", argv[1]);
for(p = res;p != NULL; p = p->ai_next) {
void *addr;
char *ipver;
// get the pointer to the address itself,
// different fields in IPv4 and IPv6:
if (p->ai_family == AF_INET) { // IPv4
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
addr = &(ipv4->sin_addr);/*error*/
ipver = "IPv4";
} else { // IPv6
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
addr = &(ipv6->sin6_addr);/*error*/
ipver = "IPv6";
}
// convert the IP to a string and print it:
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
printf(" %s: %s\n", ipver, ipstr);
}
freeaddrinfo(res); // free the linked list
return 0;
}參考資料:
Sample getaddrinfo Code Compiles in Linux but not FreeBSD
getaddrinfo(3) - Linux man page
gethostbyname(), gethostbyaddr()
Porting IPv4 applications to IPv6
Porting IPv6 -- examples
2014年11月20日 星期四
linux signal相關設定
目前在寫daemon,
寫到了處理signal的程式
signal (SIGHUP, sighup_handler);
表示當這一個process收到一個SIGHUP時,
sighup_handler這一個函式會被執行。
SIGHUP
一般是用在參考檔案更新時。
可以直接透過下指令去驗証此function是否正常
kill -HUP 3077
killall -HUP a.out
SIGTERM, SIGINT
參考資料:
Sending signal to Processes
signal 小知識
Daemon函数的用法
寫 linux daemon 的注意事項
2014年11月17日 星期一
建立samba
因為compiler環境在linux,
而產生出來的image檔案必需要傳到windows上做燒錄的動作。
找了一下,有幾個方式可以完成,
FTP
WEB
網路芳鄰
目前看起來最簡單的方式應該是網路芳鄰samba
在多天的嘗試後,可以正常的使用帳號的方式連線到linux的空間,
可惜的是還沒有辦法試成功可以用匿名的方試登入(Guest)
========== 開始 ==========
0. 查詢是否有安裝samba
rpm -q samba
1. 查詢防火牆的狀態
systemctl status firewalld
2. 關掉防火牆
systemctl disable firewalld
systemctl stop firewalld
3. 新增samba使用者
smbpasswd -a caspar
若遇到以下錯誤訊息,表示系統沒有相對應的帳號。
目前的設置是linux系統有的帳號,samba才可以追加其帳號。
4. 停用samba使用者
smbpasswd -d caspar
5. 刪除samba使用者
smbpasswd -x caspar
6. 啟用samba服務
service smb start
7. 重新啟動samba服務
service smb restart
8. 查詢目前samba的狀態
service smb status
基本上新增samba使用者後,就可以由windows進入,但是,目前成功的方試,仍然要使用帳號跟密碼。
smbpasswd這一個指令可以做一些簡單的使用者帳號的操作,
但是更深入的操作方式就必需要使用pdbedit這一個指令
========== pdbedit 指令說明 ==========
pdbedit -L
列出使用者列表
pdbedit -Lv
列出詳細的使用者列表
pdbedit -Lw
列出同 smbpasswd 格式的使用者列表
pdbedit -a jerry
新增 jerry帳號
pdbedit -x jerry
刪除 jerry帳號
pdbedit -c "[D]" -u jerry
暫時停用 jerry 這個帳號
pdbedit -c "[]" -u jerry
恢復使用 jerry 這個帳號
========== 其它資訊 ==========
linux上登入window或是samba的電腦
smbclient //主機/分享的資料匣資源 -U 使用者名稱
輸入密碼就可以執行類似ftp的指令了
mount 別台機器分享的資源到本台電腦
mount -t smbfs -o username=使用者名稱 ,password=密碼 //主機名稱/分享的資源 /主機目錄
查詢使用的port
netstat -anp
查詢目前執行的程式
ps aux | grep mbd
在設定smb.conf時, 若嘗試要設定Guest登入
設定security為share
會出現以下錯誤
WARNING: Ignoring invalid value 'share' for parameter 'security'
改為以下就可以正常的
security = user
map to guest = Bad User
========== 自己安裝 samba-4.1.13 ==========
./configure
會出現以下錯誤訊息
Could not find the python development headers
安裝以下套解可以解除問題
yum install libacl-devel libblkid-devel gnutls-devel readline-devel python-devel gdb pkgconfig
參考資料:
如何檢查linux中的服務是否正常?
Samba 設定USER等級分享目錄[3]
Samba 下 Ubuntu與Win7共享資料夾設定,利用 host-only網路
Samba-4.1.13
安裝samba系統
fedora 10/11 安裝samba || windows 與 linux 的網芳設定
第十六章、檔案伺服器之二: SAMBA 伺服器
windows 網路指令
arp
可以查詢IP與MAC相對應的列表
arp -s 157.55.85.212 00-aa-00-62-c6-09 .... 新增靜態項目。
arp -a .... 顯示 ARP 表格。